<template>
  <basic-container>
    <avue-crud :option="option"
               :data="data"
               ref="crud"
               v-model="form"
               :table-loading="loading"
               :permission="permissionList"
               @row-del="rowDel"
               @row-update="rowUpdate"
               @row-save="rowSave"
               :page="page"
               @refresh-change="refreshChange"
               @search-change="searchChange"
               @search-reset="searchReset"
               @current-change="currentChange"
               @size-change="sizeChange"
               @on-load="onLoad">
    </avue-crud>
  </basic-container>
</template>

<script>
import {
  getList,
  remove,
  update,
  add
} from "@/api/account/seller/compareBill";
import { mapGetters } from "vuex";

export default {
  data () {
    return {
      form: {},
      query: {},
      loading: true,
      rolesTree: [],
      rolesKeys: [],
      box: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      option: {
        size: 'mini',
        searchBtn:true,
        //excelBtn: true,
        tip: false,
        border: true,
        index: true,
        //selection: true,
        viewBtn: true,
        rowKey: 'id',
        height: 'auto',
        //calcHeight: 380,
        dialogType: 'dialog',
        menuWidth: 180,
        column: [
          {
            search: true,
            label: "店铺名称",
            prop: "storeName",
            fixed: true,
            rules: [{
              required: true,
              message: "请输入店铺名称",
              trigger: "blur"
            }]
          },
          {
            search: true,
            label: "支付单号",
            prop: "payOrderNum",
            rules: [{
              required: true,
              message: "请输入支付单号",
              trigger: "blur"
            }]
          },
          {
            search: true,
            label: "订单号",
            prop: "orderNo",
            rules: [{
              required: true,
              message: "请输入订单号",
              trigger: "blur"
            }]
          },
          {
            label: "支付时间",
            prop: "payTime",
            rules: [{
              required: true,
              message: "请输入支付时间",
              trigger: "blur"
            }]
          },
          {
            label: "订单金额",
            prop: "orderAmount",
            rules: [{
              required: true,
              message: "请输入订单金额",
              trigger: "blur"
            }]
          },
          {
            label: "结算金额",
            prop: "settlementAmount",
            rules: [{
              required: true,
              message: "请输入结算金额",
              trigger: "blur"
            }]
          },
          {
            search: true,
            label: "区域",
            prop: "area",
            rules: [{
              required: true,
              message: "请输入区域",
              trigger: "blur"
            }]
          },
          {
            search: true,
            label: "业务单元",
            prop: "unit",
            rules: [{
              required: true,
              message: "请输入业务单元",
              trigger: "blur"
            }]
          },
          {
            search: true,
            label: "项目",
            prop: "project",
            rules: [{
              required: true,
              message: "请输入项目",
              trigger: "blur"
            }]
          },
          {
            label: "商户号",
            prop: "businessNum",
            rules: [{
              required: true,
              message: "请输入商户号",
              trigger: "blur"
            }]
          },
          {
            search: true,
            label: "来源银行",
            prop: "sourceBank",
            rules: [{
              required: true,
              message: "请输入来源银行",
              trigger: "blur"
            }]
          },
          {
            search: true,
            label: "对账状态",
            prop: "reconciliationStatus",
            rules: [{
              required: true,
              message: "请输入对账状态 0对账失败 1对账成功",
              trigger: "blur"
            }]
          },
          {
            label: "手续费",
            prop: "handingFee",
            rules: [{
              required: true,
              message: "请输入手续费",
              trigger: "blur"
            }]
          },
          {
            label: "失败原因",
            prop: "failureReason",
            rules: [{
              required: true,
              message: "请输入失败原因 0未查询到相关订单 1订单金额不匹配",
              trigger: "blur"
            }]
          },
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(["permission", 'userInfo']),
    permissionList () {
      return {
        addBtn: this.vaildData(this.permission["/mall-cloud-base/compareBill/addItem"], false),
        viewBtn: this.vaildData(this.permission["/mall-cloud-base/compareBill/detail"], false),
        delBtn: this.vaildData(this.permission["/mall-cloud-base/compareBill/delete"], false),
        editBtn: this.vaildData(this.permission["/mall-cloud-base/compareBill/editItem"], false)
      };
    },
  },
  methods: {
    rowSave (row, loading, done) {
      row.position = row.positionIds;
      row.deptName = row.$deptId;
      row.repassword = row.password;
      add(row).then(() => {
        loading();
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
      }, error => {
        done();
        console.log(error);
      });
    },
    rowUpdate (row, index, loading, done) {
      row.position = row.positionIds;
      update(row).then(() => {
        loading();
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
      }, error => {
        done();
        console.log(error);
      });
    },
    rowDel (row) {
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return remove(row.id);
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
    },
    searchReset () {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange (params) {
      this.query = params;
      this.onLoad(this.page, params);
    },
    currentChange (currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange (pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange () {
      this.onLoad(this.page);
    },
    onLoad (page, params = {}) {
      this.loading = true;
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        this.loading = false;
        const data = res.data;
        this.page.total = data.count;
        this.data = data.data;
      });
    }
  }
};
</script>

<style>
</style>
